package com.immunology.servlets;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.immunology.model.MappingPages;
import com.immunology.model.Syndrome;
import com.immunology.service.SyndromeService;

public class RedirectSyndromeParameterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public RedirectSyndromeParameterServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		getServletContext()
		.getRequestDispatcher(MappingPages.SHOW_SYNDROME_JSP).forward(
				request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int syndromeId = 0;
		@SuppressWarnings("unchecked")
		Enumeration<String> enumeration = request.getParameterNames();
		while (enumeration.hasMoreElements()) {
			syndromeId = Integer.parseInt(enumeration.nextElement());
		}
		SyndromeService syndromeService = SyndromeService.getInstance();
		Syndrome syndrome = syndromeService.getSyndromeById(syndromeId);
		request.setAttribute("syndrome", syndrome);
		request.getRequestDispatcher(MappingPages.EDIT_SYNDROME_JSP)
				.forward(request, response);
	}

}
